﻿// =================================================================== 
// 模块说明
//====================================================================
// 创建时间：2018-12-13 22:15:00
// 负责人：Sushee
// ===================================================================
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq.Expressions;
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using OF.Utility;
using OF.Component.Model;
using OF.Component.IDAL;
using System.Text;
namespace OF.Component.DAL
{
	
	/// <summary>
	/// 数据访问层
	/// </summary>	
	internal partial class UserAuth
	{		
    
        /// <summary>
    	/// 根据断言条件获取单个
    	/// </summary>
        public UserAuthInfo QuerySingle(Expression<Func<UserAuthInfo, bool>> predicate)
	    {
            return SQLServerProvider.CreateObject(ConnectionStringKey, predicate);
        }
        
        /// <summary>
    	/// 根据断言条件获获取列表
    	/// </summary>
	    public IList<UserAuthInfo> QueryList(Expression<Func<UserAuthInfo, bool>> predicate)
	    {
	        return SQLServerProvider.CreateList(ConnectionStringKey, predicate);
	    }

        /// <summary>
        /// 获取授权信息
        /// </summary>
        /// <param name="userId">用户id</param>
        /// <returns></returns>
        public UserAuthInfo GetByUser(long userId)
        {
            Model.UserAuthInfo info = null;
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT  * FROM [UserAuth] ");
            strSql.Append("WHERE IsActive=1 AND [UserID]=@UserAuthID ");

            Database db = DatabaseFactory.CreateDatabase(this.ConnectionStringKey);
            DbCommand dbc = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbc, "@UserAuthID", DbType.Int64, userId);
            using (IDataReader dr = db.ExecuteReader(dbc))
            {
                if (dr.Read())
                {
                    info = GetByReader(dr);
                }
            }
            return info;
        }

    }
	
}